import Vue from 'vue'
import Vuex from 'vuex'
import { getApp, setApp } from '@/utils/app'
import { getUser, setUser, getRedbagUser, setRedbagUser } from '@/utils/user'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    app: getApp(),
  	user: getUser(),
    acc: {},
    answer_reslut: {
      point: '-',
      user_time: '-'
    },
    rebbag_user: getRedbagUser()
  },
  mutations: {
  	SET_APP: (state, app) => {
      setApp(app)
			state.app = app
		},
    SET_USER: (state, user) => {
      setUser(user)
      state.user = user
    },
    SET_ACC: (state, info) => {
      state.acc = info
    },
    SET_ANSWER_RESULT: (state, info) => {
      state.answer_reslut = info
    },
    SET_REBBAG_USER: (state, info) => {
      setRedbagUser(info)
      state.rebbag_user = info
    }
  },
  actions: {
  	setAPP({ commit }, app) {
  	  commit('SET_APP', app)
  	},
    SET_ACC({ commit }, info) {
      commit('SET_ACC', info)
    },
    SET_ANSWER_RESULT({ commit }, info) {
      commit('SET_ANSWER_RESULT', info)
    },
    SET_REBBAG_USER({ commit }, info) {
      commit('SET_REBBAG_USER', info)
    },
    setUSER({ commit }, user) {
      commit('SET_USER', user)
    }
  },
  modules: {
  }
})
